#!/usr/bin/env python3

# Copyright (c) 2005-2014 Fpemud <fpemud@sina.com>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.


import abc
from ._util import Util
from ._po import Flags
from ._po import HostMountPoint


class ConfigBase(abc.ABC):

    @property
    @abc.abstractmethod
    def flags(self):
        pass

    @abc.abstractmethod
    def get_build_variable(self, var_name):
        pass

    @abc.abstractmethod
    def get_boot_mode(self):
        pass

    @abc.abstractmethod
    def get_system_init(self):
        pass

    @abc.abstractmethod
    def get_mount_points(self):
        pass

    @abc.abstractmethod
    def get_fs_layout(self):
        pass

    # FIXME
    @abc.abstractmethod
    def get_remount_boot_rw(self):
        pass

    # FIXME
    @abc.abstractmethod
    def get_bootloader_extra_time(self):
        pass

    # FIXME
    @abc.abstractmethod
    def get_kernel_extra_init_cmdline(self):
        pass

    def _assertValid(self):
        if self.flags == Flags.KERNEL:
            pass
        elif self.flags == (Flags.KERNEL | Flags.INITRAMFS):
            pass
        elif self.flags == (Flags.BOOTLOADER | Flags.KERNEL | Flags.INITRAMFS):
            pass
        elif self.flags == (Flags.BIOS | Flags.BOOTLOADER | Flags.KERNEL | Flags.INITRAMFS):
            pass
        else:
            assert False

        if len(self.get_mount_points()) > 0:
            if not all([isinstance(x, HostMountPoint) for x in self.get_mount_points()]):
                assert False
            if not Util.checkListUnique(self.get_mount_points(), key=lambda x: x.mountpoint):
                assert False
            if not self.get_mount_points()[0].mountpoint == "/":
                assert False
